<? include "server_config.php";?>
				
				<div style="width:30px;height:30px;float:left;"></div>
				<div style="width:600px;float:left;">
					쪽지 목록<br>
					<div style="width:100%;height:5px;float:left;"><span></span></div>
				</div>

				<div style="width:100%;height:15px;float:left;"><span></span></div>

				<div style="width:100%;height:1px;background:gray;float:left;"><span></span></div>
				<div style="width:100%;height:2px;background:#ffffff;float:left;"><span></span></div>

				<div style="width:100%;height:15px;float:left;"><span></span></div>
				<br/>


			<!-- 쪽지 리스트 출력 시작-->
			<? 

				$sql_count ="
					SELECT COUNT(A.memo_idx)
					FROM ndd_memo A
					WHERE 
					A.user_idx= ".$user_idx." OR
					A.target_idx= ".$user_idx.";";


				$sql="
					SELECT A.memo_idx, A.user_idx, A.target_idx, A.content, B.nickname, A.reg_timestamp, A.read_timestamp
					FROM ndd_memo A, ndd_user B
					WHERE 
					(A.user_idx= ".$user_idx." AND A.target_idx = B.user_idx) OR
					(A.target_idx= ".$user_idx." AND A.user_idx = B.user_idx)
					
					";

				$sql.="
					ORDER BY A.reg_timestamp DESC LIMIT ".($page)*$article_per_page." ";

				//echo $sql;
				$result = mysql_query($sql,$connect);

				while($row = mysql_fetch_row($result))
				{
					$memo_idx = $row[0];
					$memo_content = $row[3];

					if($row[1]==$user_idx)
					{
						//내가 보낸 쪽지이면
						$friend_user_idx = $row[2];
						$memoFromMe = true;

					}
					else
					{
						$friend_user_idx = $row[1];
						$memoFromMe = false;
					}
					

				
					$friend_user_nickname = $row[4];

			?>

					<div style="width:100%;float:left;">
						<div style="width:60px;height:80px;float:left;">
						
						<?
						if($memoFromMe)
						{
							//내가 보낸 쪽지이면
							echo "<font color='blue' size='5'>▶</font><br><font color='blue'>보낸쪽지</font>";
						}
						else
						{
							echo "<font color='red' size='5'>◀</font><br><font color='red'>받은쪽지</font>";

						}

						?>
						</div>
						
						
						
						<!-- 친구 프로필 출력 시작 -->


						<div style='width:73px;height:85px;float:left;'>
						<?
							$user_img = "./upload/member_photo/".$friend_user_idx;

							if(file_exists($user_img)){
						?>
							<img src="<? echo $user_img; ?>" width="73px" height="73px" border=0>
						<?
							}
							else
							{
						?>
						<?
							}
						?>	
						</div>



						<div style='width:15px;height:85px;float:left;'>
						</div>

						<div style='width:150px;height:85px;float:left;'>
							<span id='list_id'><? echo $friend_user_nickname;?><br></span>
							<span id='list_id_detail'>



						<? 
						
							$sql_2="
								SELECT birthday, sex FROM ndd_user_expand WHERE user_idx = $friend_user_idx LIMIT 1;
							";
									
							$result_2 = mysql_query($sql_2,$connect);
				
							$row2 = mysql_fetch_row($result_2);

							if($row2[1]=="M")
								echo "남";
							else if($row[1]=="F")
								echo "여";
							else 
								echo "(미입력)";
							
							echo " / ";

							if($row[0]!="0000-00-00" && $row2[0]!="")
							{

								//생일 입력
								$myBirthDate    = strtotime($row2[0]);

								//만나이
								$birthDate1     = date( 'Ymd', $myBirthDate );
								$nowDate1       = date('Ymd');
								$age1           = floor(($nowDate1 - $birthDate1) / 10000);

								//한국 나이
								$birthDate2     = date( 'Y', $myBirthDate );
								$nowDate2       = date('Y');
								$age2           = $nowDate2 - $birthDate2 + 1 ;

								echo $age2."세";
							}
							else
							{
								echo "(미입력)";

							}
				
						?>				
							<br>
							류마점수 3점<br>
							회원등급 2급 ★★
							</span>

						</div>


						<!-- 친구 프로필 출력 끝 -->


						<!-- 메모 내용 출력 시작 -->

						<div style='width:303px;float:left;' id='div_memo_<? echo $row[0];?>_long'>
							<?=$memo_content?>
							<br/><br/>							
						</div>

						<!-- 메모 내용 출력 끝 -->

						<div style='width:80px;float:right;'>

							<? echo substr($row[5],0,10); //보낸시각?><br/>
							<? if($memoFromMe && $row[6]=='0000-00-00 00:00:00')
							{
								echo "읽지않음<br/>";
							}
							else if($memoFromMe)
							{
								echo "읽음<br/>";
							} else if(!$memoFromMe && $row[6]=='0000-00-00 00:00:00')
							{
								?>
								<script>
		//							memo_read(<?=$memo_idx?>);
									$.post(
										"memo_read.php", //서버측 스크립트 언어
										{	'idx': <?=$memo_idx?> 
										}, //쿼리스트링?키1=값1&키2=값2
										function (data) {         //콜백함수 : 결과값 받기 , data로 받아옴  
										}
									)
								</script>
								<?
							}
							?>
							

							<? if(!$memoFromMe) { ?>
							<a onclick="show_user_menu_reply(<? echo $row[1];?>, '<? echo $row[4];?>');" style="cursor:pointer;">답장하기</a> &nbsp;
							<? } ?>

							<!--a href='friends_del.php?friend_idx=<? echo $friend_idx; ?>'><img src='./img/button_friend_del.png' alt='친구끊기' border="0"></a-->
						</div>

					</div>

					<div style="width:100%;height:5px;float:left;"><span></span></div>

					<div style="width:100%;height:1px;background:gray;float:left;"><span></span></div>
					<div style="width:100%;height:2px;background:#ffffff;float:left;"><span></span></div>

					<div style="width:100%;height:5px;float:left;"><span></span></div>
					<br/>





			<!--div style="width:600px;height:26px; vertical-align : middle; cursor:pointer;" id='div_memo_<? echo $row[0];?>_short' onclick="memo_extend( <? echo $row[0];?> ,true);">
				<div style="width:100px;height:20px;float:left; text-align:center;">
					<? echo $row[4]; ?>	
				</div>
				<div style="width:300px;float:left;" id='div_memo_<? echo $row[0];?>_short'>
					<? echo mb_substr($row[3], 0, 20, 'UTF-8');  ?>...
				</div>
				<div style="width:100px;height:20px;float:left; text-align:center;" id="div_read_or_not_<? echo $row[0];?>">
					<? if($row[6]=='0000-00-00 00:00:00')
					{
						echo "읽지않음";
						?>
						<script>
							$('#div_memo_<? echo $row[0];?>_short').css('color','#cccccc');
						</script>
						<?
					}
					else
					{
						echo "읽음";
					}
					?>

				</div>
				<div style="width:100px;height:20px;float:left; text-align:center;">
					<? echo substr($row[5],0,10); //보낸시각?>
				</div>

			</div>

			<div style="width:600px;vertical-align : middle; display:block;" id='div_memo_<? echo $row[0];?>_long' >
				<div style="width:100px;height:20px;float:left; text-align:center;">
					<? echo $row[4]; ?>	
				</div>
				<div style="width:300px;float:left;">
					<p align='right'>
						(<? echo $row[5]; //보낸시각?>) 
						<? if($box=='receive') { ?>
						<a onclick="show_user_menu_reply(<? echo $row[1];?>, '<? echo $row[4];?>');" style="cursor:pointer;">답장하기</a> &nbsp;
						<? } ?>
						<a onclick="memo_extend( <? echo $row[0];?> ,false);" style='cursor:pointer;'>닫기</a>
					</p>
					<? echo conver_html($row[3]);?>
					<br>
					<br>

				</div>

				<div style="width:100px;height:20px;float:left; text-align:center;">
					<? if($box=='send' && $row[6]=='0000-00-00 00:00:00')
					{
						echo "읽지않음";
						?>
						<script>
							$('#div_memo_<? echo $row[0];?>_long').css('color','#cccccc');
						</script>
						<?
					}
					else
					{
						echo "읽음";
					}
					?>

				</div>
				<div style="width:100px;height:20px;float:left; text-align:center;">
					<? echo substr($row[5],0,10); //보낸시각?>
				</div>
				
			</div>

			<script>
				$('#div_memo_<? echo $row[0];?>_long').hide();
			</script>


			<div style="clear:both;"></div>
			<div style="width:600px;height:1px;background:#cccccc;"><span></span></div>
			<div style="clear:both;"></div-->
			<?
				}

			?>
			<!-- 쪽지 리스트 출력 끝-->


			<?
				$result = mysql_query($sql_count,$connect);

				$row = mysql_fetch_row($result);

				$document_count = $row[0];
			?>
			<script>
			$('#memo_count').text('<?=$document_count?>');
			</script>
			<?
				if($page == floor(($document_count-1)/$article_per_page)+1 )
				{
				?>
						<div style='height:30px;width:100%;float:left;'><span></span></div>
						
						<div style='height:60px;width:100%;float:left;text-align:center;'>
						마지막 페이지 입니다.</div>
				<?
				}
				else
				{
				?> 
						<div style='height:30px;width:100%;float:left;'><span></span></div>
						<div style='float:left;height:50px;width:100%;text-align:center;'><span>
						<img id="img_show_more" src="./img/talk_view_more.png" alt="더보기" style="cursor:pointer;border:0px;" onclick="memo_display_list('<? echo $page+1;?>' ); " />
						</span>
						</div>
						<div style='height:30px;width:100%;float:left;'><span></span></div>
					
				<?
				}


				?>





		<script>
/*
		function memo_read(memo_idx)
		{
			alert(memo_idx);
			$.post(
				"memo_read.php", //서버측 스크립트 언어
				{	'idx': memo_idx 
				}, //쿼리스트링?키1=값1&키2=값2
				function (data) {         //콜백함수 : 결과값 받기 , data로 받아옴  
				}
			)

		}

		function memo_extend(memo_idx, open)
		{
			if(open)
			{
				$('#div_memo_'+memo_idx+'_short').hide();
				$('#div_memo_'+memo_idx+'_long').show();

				<? if($box!="send") { ?>

				$.post(
					"memo_read.php", //서버측 스크립트 언어
					{	'idx': memo_idx 
					}, //쿼리스트링?키1=값1&키2=값2
					function (data) {         //콜백함수 : 결과값 받기 , data로 받아옴  
						//$('#pnlDisplay').html(data);
		//				$('#commentDisplay').load('my_info_main_comment.php', {'info_idx' : '<? echo $info_idx; ?>', 'user_idx' : '<? echo $user_idx; ?>', 'disease_idx' : '<? echo $disease_idx; ?>'});
		//						alert(data);
					}
				)


				$('#div_read_or_not_'+memo_idx).html('읽음');
				
				<? } ?>

			}
			else
			{
				$('#div_memo_'+memo_idx+'_long').hide();
				$('#div_memo_'+memo_idx+'_short').show();


				<? if($box!="send") { ?>

				$('#div_memo_'+memo_idx+'_short').css('color','#000000');

				<? } ?>
			}


		}*/

		page = '<?=$page?>';

		</script>